#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
typedef int  Status;
typedef int  ElemType;
int num = 0;
typedef struct BiTNode {
    ElemType data;
    struct BiTNode *lchild, *rchild;
} BiTNode, *BiTree;
BiTNode* node = NULL;
Status InsertBiTree(BiTree &T, int e) {
    if(T == NULL) {
        T = new BiTNode;
        T->data = e;
        T->lchild = T->rchild = NULL;
        return 1;
    }
    T->data < e ? InsertBiTree(T->rchild, e) : InsertBiTree(T->lchild, e);
    return 0;
}
Status PrintElement(ElemType e) {
    printf("%d ", e);
    return 1;
}
Status PreOrderTraverse(BiTree T, Status(*Visit)(ElemType)) {
    if(T == NULL)  return 0;
    Visit(T->data);
    PreOrderTraverse(T->lchild, Visit);
    PreOrderTraverse(T->rchild, Visit);
    return 1;
}

Status InOrderTraverse(BiTree T, Status(*Visit)(ElemType)) {
    if(T == NULL)  return 0;
    InOrderTraverse(T->lchild, Visit);
    Visit(T->data);
    InOrderTraverse(T->rchild, Visit);
    return 1;
}

Status PostOrderTraverse(BiTree T, Status(*Visit)(ElemType)) {
    if(T == NULL)  return 0;
    PostOrderTraverse(T->lchild, Visit);
    PostOrderTraverse(T->rchild, Visit);
    Visit(T->data);
    return 1;
}
void FindNode(BiTree Ta, int i) {
    if(Ta == NULL) return;
    if(Ta->lchild) FindNode(Ta->lchild, i);
    if(++num == i) node = Ta;
    if(Ta->rchild) FindNode(Ta->rchild, i);
}
int main() {
    freopen("data.txt","r",stdin);
    BiTree T = NULL;
    int n, e;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> e;
        InsertBiTree(T, e);
    }
    PreOrderTraverse(T, PrintElement);
    cout << endl;
    InOrderTraverse(T, PrintElement);
    cout << endl;
    PostOrderTraverse(T, PrintElement);
    cout << endl;
    int key;
    cin >> key;
    FindNode(T, key);
    if(key > n || key < 1) cout << "Error" << endl;
    else cout << node->data << endl;
    num = 0;
    cin >> key;
    FindNode(T, key);
    if(key > n || key < 1) cout << "Error" << endl;
    else cout << node->data << endl;
    return 0;
}
